<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Category;
use app\common\model\Events;
use app\common\model\Goods;
use app\common\model\order\Order;
use app\common\model\User;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $site_name = config('site.name');
        $carousel_images = image_processing('images', config('site.carousel_images'));
        $events = Events::limit(3)->select();
        $recommended_goods = Goods::all(['state' => '2']);
        $pinned_goods = Goods::where(['pinned' => '2'])->order('id desc')->limit(4)->select();
        $this->success('请求成功', compact('site_name', 'carousel_images', 'events', 'recommended_goods', 'pinned_goods'));
    }

    /**
     * @Author LK
     * @ApiTitle (标签)
     * @ApiMethod (POST)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="ID")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function tag()
    {
        $list = Category::all(['type' => 'Site_icon']);
        $this->success('请求成功', $list);
    }
    /**
     * @Author LK
     * @ApiTitle (更新坐标)
     * @ApiMethod (POST)
     * @ApiParams (name="lng", type="string", required=true, sample="", description="经度")
     * @ApiParams (name="lat", type="string", required=true, sample="", description="纬度")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function coordinate()
    {
        $param = request()->param();
        extract($param);
        $user = User::get($this->auth->id);
        $user->lng = $lng;
        $user->lat = $lat;
        $user->save();
        $this->success();
    }
}
